// ----------------------------------------
// Filename: Link_List.h
// Description: The header file for a bi-directional linked list
// Author: Jon Maloney
// Date: 9-May-2012
//

#ifndef LIST_H
#define LIST_H

//************************************************************
//                    Include .h files
//************************************************************
	
//************************************************************
//                    Include external references
//************************************************************
#include "types.h"
#include "configuration.h"
//************************************************************
//                    Define Statements
//************************************************************

//************************************************************
//                    Struct, Union, enum Statements
//************************************************************

struct TLINKED_LIST
{
	void * Item;								/*< Pointer to the value being stored in the list. */
	volatile struct TLINKED_LIST * NextNode;	/*< Pointer to the next Node in the list. */
	volatile struct TLINKED_LIST * PreviousNode;/*< Pointer to the previous Node in the list. */
};

typedef struct TLINKED_LIST TLINKED_LIST;
typedef struct TLINKED_LIST * linkedList_Handle;

//************************************************************
//                    Global variables and constants
//************************************************************

//************************************************************
//                    Prototype Global Functions
//************************************************************

// ----------------------------------------
// LinkList_Add
// 
// Adds an Node to a link list.
//	If a new list Node needs to be created
//	this function will create the new list Node
//	and return this list Node's handle.
// Input:
// 	currentListNode: 	the list Node that the new Node is to be inserted into.
//	newItem:			The item that is to be inserted into the list.
// Output:
//  A handle to the link list that was created.
// Conditions:
// 	none
//
linkedList_Handle LinkedList_Add( linkedList_Handle currentListNode, void * newItem );

// ----------------------------------------
// LinkList_Insert
// 
// Inserts a new list Node into a current lits.
// Input:
// 	currentListNode: 	The list Node that the new list Node is to be inserted into.
//	newListNode:		The list Node that is to be inserted into the list.
// Output:
//  A handle to the link list that was created if createdListNode is NULL
// Conditions:
// 	none
//
linkedList_Handle LinkedList_Insert(linkedList_Handle currentListNode, linkedList_Handle newListNode);

// ----------------------------------------
// LinkedList_Remove
// 
// Removes an Node from the link list.
//	(DOES not delete the node)
//		See LinkList_Delete for a delete and remove function
// Input:
// 	listNodeToRemove:	The link list Node to be removed from the link list
// Output:
//  pdTRUE 	if there are elements remaining in the linked list
//	pdFALSE	if there are NO elements remaining in the linked list.
// Conditions:
// 	none
//
BOOL LinkedList_Remove(linkedList_Handle ListNodeToRemove);

// ----------------------------------------
// LinkList_Move
// 
// Moves an Node from one list to another
// Input:
//  moveFrom: 	The list that the task is to be moved from
//	moveTo:		The list that the task to the be moved into
// Output:
//  none
// Conditions:
// 	none
//
BOOL LinkedList_Move(linkedList_Handle moveFrom, linkedList_Handle moveTo );

// ----------------------------------------
// LinkList_DeleteNode
// 
// Removes an Node from the link list and free's the memory allocated to the Node
//	and frees the memory allocated to the Item in the node.
// Input:
// 	ListNodeToDelete:	The link list Node to be removed from the link list
// Output:
//  pdTRUE 	if there are elements remaining in the linked list
//	pdFALSE	if there are NO elements remaining in the linked list.
// Conditions:
// 	none
//
BOOL LinkedList_DeleteNode(linkedList_Handle ListNodeToDelete);

#endif 
